<template>
  <div>
    <el-form label-width="80px" :inline="true">
      <el-form-item label="年级">
        <nice-select
          v-model="search.school"
          placeholder="请选择年级"
          clearable
        ></nice-select>
      </el-form-item>
      <el-form-item label="辅导老师">
        <nice-select
          v-model="search.status"
          placeholder="请选择辅导老师"
          clearable
        ></nice-select>
      </el-form-item>
      <el-form-item label="科目">
        <nice-select
          v-model="search.status"
          placeholder="请选择科目"
          clearable
        ></nice-select>
      </el-form-item>
      <el-form-item label="课程名称">
        <nice-select
          v-model="search.area"
          placeholder="请选择课程名称"
          clearable
        ></nice-select>
      </el-form-item>
      <el-form-item label="期次">
        <nice-select
          v-model="search.status"
          placeholder="请选择期次"
          clearable
        ></nice-select>
      </el-form-item>
      <el-form-item label="学生">
        <el-input
          v-model="search.name"
          placeholder="请输入学生姓名/联系方式"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit" size="small"
          >搜索</el-button
        >
      </el-form-item>
      <div class="right">
        <el-form-item>
          <el-button type="primary" @click="handleBatchAllocationr" size="small"
            >批量分班</el-button
          >
          <el-button type="primary" @click="handleBatchAdjust" size="small"
            >批量调班</el-button
          >
          <el-button type="primary" @click="handleClassManage" size="small"
            >班级管理</el-button
          >
        </el-form-item>
      </div>
    </el-form>
    <el-table :data="list" border header-cell-class-name="thead">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column
        v-for="(col, index) in table"
        :prop="col.prop"
        :label="col.label"
        :formatter="col.formatter"
        :width="col.width"
        :key="index"
      ></el-table-column>
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="text"
            @click="handleAllocation(scope.row)"
            >分班</el-button
          >
          <el-button size="small" type="text" @click="handleAdjust(scope.row)"
            >调班</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      @current-change="handleCurrentChange"
      :current-page="search.pageNum"
      :page-size="search.pageSize"
      layout="prev, pager, next,jumper"
      :total="total"
    >
    </el-pagination>
    <el-dialog
      :title="title"
      :visible.sync="isDialog"
      @close="isDialog = false"
      width="500px"
    >
      <el-form
        :model="classForm"
        :rules="classFormRules"
        ref="classForm"
        label-width="80px"
      >
        <el-form-item
          label="当前班级"
          prop="currentClass"
          v-if="mode == 'adjust'"
        >
          <el-input
            v-model="classForm.currentClass"
            placeholder=""
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="选择班级" prop="class">
          <nice-select
            v-model="classForm.class"
            placeholder="请选择班级"
            clearable
          ></nice-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isDialog = false" size="small">取消</el-button>
        <el-button type="primary" @click="handleSave" size="small"
          >确定</el-button
        >
      </span>
    </el-dialog>
    <!-- 班级管理 -->
    <class-manage v-if="classManageDialog" ref="classManage"></class-manage>
  </div>
</template>
<script>
import base from "@/views/base.vue";
import ClassManage from "./components/class-manage.vue";
export default {
  name: "class-assignment",
  extends: base,
  data() {
    return {
      search: {
        name: "",
        area: "",
        school: "",
        status: "",
        pageSize: 10,
        pageNum: 1
      },
      list: [{ name: "222" }],
      isDialog: false,
      classManageDialog: false,
      title: "",
      table: [
        {
          label: "学生姓名",
          prop: "name"
        },
        {
          label: "联系方式",
          prop: "phone"
        },
        {
          label: "性别",
          prop: "sex"
        },
        {
          label: "课程名称",
          prop: "school"
        },
        {
          label: "期次",
          prop: "class"
        },
        {
          label: "辅导老师",
          prop: "resource"
        },
        {
          label: "班级",
          prop: "address"
        }
      ],
      total: 0,
      classFormRules: {
        class: [{ required: true, message: "请选择班级", trigger: "change" }]
      },
      classForm: {
        class: "",
        currentClass: ""
      },
      mode: "allocation"
    };
  },
  activated() {
    this.getData();
  },
  components: {
    ClassManage
  },
  methods: {
    async getData() {},
    onSubmit() {
      this.search.pageNum = 1;
      this.getData();
    },
    handleBatchAllocationr() {
      this.isDialog = true;
      this.title = "分班";
      this.mode = "allocation";
    },
    handleBatchAdjust() {
      this.isDialog = true;
      this.title = "调班";
      this.mode = "adjust";
    },
    handleClassManage() {
      this.classManageDialog = true;
      this.$nextTick(() => {
        this.$refs.classManage.init();
      });
    },
    handleCurrentChange(val) {
      this.search.pageNum = val;
      this.getData();
    },
    handleAllocation(row) {
      this.isDialog = true;
      this.title = "分班";
      this.mode = "allocation";
    },
    handleAdjust(row) {
      this.isDialog = true;
      this.title = "调班";
      this.mode = "adjust";
    },
    handleSave() {}
  }
};
</script>
<style lang="scss" scoped></style>
